package map05;

import java.util.HashMap;
import java.util.Map;

public class HashMapDemo01 {
    public static void main(String[] args) {
        HashMap<String, Student> students = new HashMap<>();

        Student s1 = new Student("01", "张三");
        Student s2 = new Student("05", "李四");
        Student s3 = new Student("07", "王五");

        students.put(s1.getSno(), s1);
        students.put(s2.getSno(), s2);
        students.put(s3.getSno(), s3);

        //利用keySet方法遍历
        for (String key : students.keySet()) {
            System.out.println(key+" "+students.get(key));
        }

        //利用entrySet方法遍历
        for (Map.Entry<String,Student> me : students.entrySet()){
            String key = me.getKey();
            Student s = me.getValue();
            System.out.println(key+" "+s.getName());
        }
    }
}
